import Vue from "vue";
import Router from "vue-router";
import NProgress from "nprogress";

// import partner from "./partner";
// import activity from "./activity";

Vue.use(Router);

const routes = [
  {
    name: "index",
    path: "/index",
    component: () => import("@/views/index.vue")
  },
  {
    name: "login",
    path: "/login",
    component: () => import("@/views/login/index.vue")
  },
  {
    name: "product",
    path: "/product",
    component: () => import("@/views/product/index.vue")
  },
  {
    name: "product-detail",
    path: "/product/:id",
    component: () => import("@/views/product/_id.vue")
  },
  // ...activity,
  // ...partner,
  {
    path: "*",
    redirect: "/index"
  }
];

// add route path
// routes.forEach(route => {
//   route.path = route.path || "/" + (route.name || "");
// });

const router = new Router({
  routes,
  scrollBehavior(to, from, savedPosition) {
    return {
      x: 0,
      y: 0
    };
  }
});

NProgress.configure({
  showSpinner: false
}); // NProgress Configuration

router.beforeEach((to, from, next) => {
  NProgress.start(); // start progress bar
  // console.log(to, from);
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  next();
});
router.afterEach(() => {
  NProgress.done(); // finish progress bar
});

export { router };
